<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
            //通过POST拿到注册信息 POST是全局定义的关联数组
            echo "adduser<br>";
            $username=$_POST['username'];
            $pwd=$_POST['password'];
            echo $username,$pwd;
        ?>
        
        <?php
            //连接数据库并执行插入操作
            //第一步：连接数据库

            $host = "localhost";
            $user = "root";
            $password = "";
            $database = "itcast";
            $link=mysqli_connect($host, $user, $password);
            //设置需要操作的数据库名称
            mysqli_select_db($link, $database);
            //设置数据库的字符编码
            mysqli_set_charset($link, "utf8");
           
            //第二步：操作数据库的表（操作：插入，查询，删除，更新）
            //执行插入sql语句
            $sql = "INSERT INTO shop_user(username,PASSWORD,salt)VALUES('$username',SHA1('$pwd'),'8m40bf');";
            echo "<br>$sql <br>";
            $result=  mysqli_query($link, $sql);
            var_dump($result);

            //第三步：结果判断
            if ($result){
//                echo "<script>alert('注册成功！');</script>";
//                //header可以指定转到到某个页面
//                header("Location:login.php");
                go_forward("注册成功", "login.php");
            }else{         
//                echo "<script>alert('注册失败！');</script>";
//                header("Location:register.php");
                go_forward("注册失败", "register.php");
            }
        ?>
    </body>
</html>
